<template>
  <div class="content">
    <div id="main" style="width: 600px;height:400px;"></div>
    <div id="right" style="width: 600px;height:400px;margin-left: 50px;"></div>
  </div>
</template>
  
<script setup>
import * as echarts from 'echarts';
import { ref, getCurrentInstance, computed, onBeforeMount, onMounted, toRefs } from 'vue';
import { getListenRecord } from '@/api/music/music.ts'

const listenRecord = ref([
  { value: 735, name: 'Direct' },
  { value: 580, name: 'Email' },
  { value: 484, name: 'Union Ads' },
  { value: 300, name: 'Video Ads' }])

  const listenRecordSinger = ref([
  { value: 735, name: 'Direct' },
  { value: 580, name: 'Email' },
  { value: 484, name: 'Union Ads' },
  { value: 300, name: 'Video Ads' }])
const aa = (listenRecord) => {
  var chartDom = document.getElementById('main');
  var myChart = echarts.init(chartDom);
  var option;

  option = {
    title: {
      text: '喜欢听的音乐',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '10%',
      left: 'center'
    },
    series: [
      {
        name: '音乐',
        type: 'pie',
        radius: ['30%', '70%'],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: listenRecord
      }
    ]
  };

  option && myChart.setOption(option);


}

const bb = (listenRecord) => {
  var chartDom = document.getElementById('right');
  var myChart = echarts.init(chartDom);
  var option;

  option = {
    title: {
      text: '喜欢听的歌手',
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '10%',
      left: 'center'
    },
    series: [
      {
        name: '歌手',
        type: 'pie',
        radius: ['20%', '70%'],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: listenRecord
      }
    ]
  };

  option && myChart.setOption(option);


}
onMounted(async () => {

  const res = await getListenRecord()
  listenRecord.value = res.echartsDTOSMusic
  listenRecordSinger.value= res.echartsDTOSSinger
  aa(listenRecord.value)
  bb(listenRecordSinger.value)
})
</script>
<style scoped>
.content{
  display: flex;
}
</style>